﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext.Web;

public partial class Provider_ReportAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Store3Bind();
    }
     
    protected  void SubmitForm(object s,AjaxEventArgs e)
    {
        CxProvider p=new CxProvider();
        p.ProviderName = TfProviderName.Text;
        p.DeviceName = TfDeviceName.Text;
        if (tfsham_time.Value.ToString() != "0001/1/1 0:00:00")
        {
            p.ShamTime = DateTime.Parse(tfsham_time.Value.ToString()); 
        }
        p.ShamProject = tfsham_project.Text;
        p.ShamDetail = tfshame_detail.Text;
        if (tfxinghu_time.Value.ToString() != "0001/1/1 0:00:00")
        {
            p.XinghuTime = DateTime.Parse(tfxinghu_time.Value.ToString());
        }
        p.XinghuProject = tfxinghu_project.Text;
        p.XinghuDetail = tfxinghui_detail.Text;
        if (tfcontract_time.Value.ToString() != "0001/1/1 0:00:00")
        {
            p.ContractTime = DateTime.Parse(tfcontract_time.Value.ToString());
        }
        p.ContractProject = tfcontract_project.Text;
        p.ContractDetail = tfcontract_detail.Text;
        p.OtherDetail = tfother_detail.Text;
        p.EnteringUserid = int.Parse(Cookies.getCookies("cuid"));
        if (tfdept_master_id.SelectedIndex == -1) {
            Err.Warning("请选择部门领导！",MessageBox.Icon.WARNING);
            return;
        }
        p.DeptMasterId = int.Parse(tfdept_master_id.SelectedItem.Value);
        p.DeptMasterStatus = 0;
        p.TechMasterId = 0;
        p.OfficeMasterId = 0;
        p.BossId = 0;
        p.InTime = DateTime.Now;
        Guid g = Guid.NewGuid();
        p.Guid = g;
        CXFileUpload.Sv(tffileupload,g);
        p.Save();
        Clear();
        Err.Warning("已经提交至相关领导审核。",MessageBox.Icon.NONE);
        
    }
    protected void Clear()
    {
        TfProviderName.Text = "";
        TfDeviceName.Text = "";
        tfsham_time.Clear();
        tfcontract_detail.Text = "";
        tfcontract_project.Text = "";
        tfcontract_time.Clear();
        tfdept_master_id.Reset();
        TfDeviceName.Text = "";
         
        tfother_detail.Text = "";
        TfProviderName.Text = "";
        TfProviderName.Text = "";
        tfsham_project.Text = "";
        tfsham_time.Clear();
        tfshame_detail.Text = "";
        tfxinghu_project.Text = "";
        tfxinghu_time.Clear();
        tfxinghui_detail.Text = "";
    }
    protected void Store3Bind()
    {
        int deptId = int.Parse(Cookies.getCookies("cDeptID"));
        if (deptId > 10)
        {
            Query q = new Query(CxSysDept.Schema);
            q.SetSelectList("deptid");
            q.AddWhere("ID", deptId);
            deptId = int.Parse(q.ExecuteScalar().ToString());
        }
        Query q2 = new Query(CxUserBase.Schema);
        q2.SetSelectList("username,uID");
        q2.AddWhere("levelid", 1);
        q2.AddWhere("depid", deptId);
        Store3.DataSource = q2.ExecuteDataSet();
        Store3.DataBind();
    }
    protected int getDeptId(int deptId)
    {
        if (deptId > 10)
        {
            Query q = new Query(CxSysDept.Schema);
            q.SetSelectList("deptid");
            q.AddWhere("ID", deptId);
            deptId = int.Parse(q.ExecuteScalar().ToString());
        }
        return deptId;
    }
}
